package cn.edu.seu.herald.informationplatform.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.edu.seu.herald.informationplatform.dao.cookie.LeagueUserSessionCookieAccess;
import cn.edu.seu.herald.informationplatform.dao.database.PictureDao;

public class PictureEdit extends HttpServlet {

	/**
	 * Constructor of the object.
	 */
	public PictureEdit() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		try{
			PictureDao pictureDao = PictureDao.getDao();
			System.out.println(Integer.parseInt(request.getParameter("picture"))+request.getParameter("newName"));
			pictureDao.updatePictureName(Integer.parseInt(request.getParameter("picture")),request.getParameter("newName"));
			LeagueUserSessionCookieAccess luSessionCookieAccess =new LeagueUserSessionCookieAccess(request);
			String albumId=request.getParameter("albumId");
			response.sendRedirect("./album.jsp?league="+luSessionCookieAccess.getLeagueId()+"&album="+albumId);
		}catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void init() throws ServletException {
		// Put your code here
	}

}
